package com.aaa.reflection.demo6;

import java.lang.reflect.Method;

/**
 * @author C-Q
 * @version 1.1.0
 * @Description: Method类中常用的方法
 * @date 2022/10/27
 */
public class Test01 {
    public static void main(String[] args) throws Exception{
        Class<?> aClass = Class.forName("com.aaa.reflection.demo6.Dog");
        //1获取方法名和参数获取本类中指定的方法对象
        Method sleep = aClass.getDeclaredMethod("sleep");

        //普通：对象名.方法(实参) 反射：方法对象.invoke(对象名,实参)
        Object o = aClass.newInstance();
        Object invoke = sleep.invoke(o);//方法回调
//        System.out.println("invoke ==== " + invoke);

        Method each = aClass.getDeclaredMethod("each", String.class, Integer.class);
        Object invoke1 = each.invoke(o, "程序员", 22);
        System.out.println("invoke1 = " + invoke1);
    }
}

class Cat{
    public void fan(){
        System.out.println("风扇的fan方法");
    }
    private void fan01(){
        System.out.println("风扇的fan01方法");
    }
}
class Dog extends Cat {
    public void sleep(){
        System.out.println("Dog中的sleep方法");
    }
    public void each(String job,Integer time){
        System.out.println("Dog中的each方法");
    }
}